package com.java.process.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.java.common.utils.R;
import com.java.model.process.ProcessType;
import com.java.process.service.ProcessTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/process/processType")
@Api(tags = "审批管理")
public class ProcessTypeController {

    @Autowired
    private ProcessTypeService processTypeService;

    @GetMapping("/findAll")
    public R findAll(){
        List<ProcessType> list = processTypeService.list();
        return R.ok(list);
    }
   // @PreAuthorize("hasAuthority('bnt.processType.list')")
    @ApiOperation("获取分页列表")
    @GetMapping("{page}/{limit}")
    public R index(@PathVariable Long page,@PathVariable Long limit){
        Page<ProcessType> pageParam = new Page<>(page,limit);
        Page<ProcessType> processTypePage = processTypeService.page(pageParam);
        return R.ok(processTypePage);
    }
    //@PreAuthorize("hasAuthority('bnt.processType.list')")
    @ApiOperation(value = "获取")
    @GetMapping("get/{id}")
    public R get(@PathVariable Long id) {
        ProcessType processType = processTypeService.getById(id);
        return R.ok(processType);
    }

   // @PreAuthorize("hasAuthority('bnt.processType.add')")
    @ApiOperation(value = "新增")
    @PostMapping("save")
    public R save(@RequestBody ProcessType processType) {
        processTypeService.save(processType);
        return R.ok();
    }

   // @PreAuthorize("hasAuthority('bnt.processType.update')")
    @ApiOperation(value = "修改")
    @PutMapping("update")
    public R updateById(@RequestBody ProcessType processType) {
        processTypeService.updateById(processType);
        return R.ok();
    }

    //@PreAuthorize("hasAuthority('bnt.processType.remove')")
    @ApiOperation(value = "删除")
    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable Long id) {
        processTypeService.removeById(id);
        return R.ok();
    }

}
